module majiang.Views {
    export class Play extends eui.Component {
        //eui
        public xuanArea:majiang.Views.XuanArea;
        public hupaiArea:majiang.Views.HupaiArea;
        public hupaiBtn:majiang.Views.HupaiBtn;
        public scoreBoard:majiang.Views.ScoreBoard;
        
        //data
        public fanshu:number = 0;
        public hupaishu:number = 0;

        constructor(){
            super();

            majiang.Controllers.Play.view = this;
            this.once(eui.UIEvent.CREATION_COMPLETE,this.skinCreationComplete,this);
            this.skinName = "playSkin";
        }

        private skinCreationComplete(){
            majiang.Datas.Playing.shengyuPai = new majiang.Datas.PaiChi();
            majiang.Datas.Playing.shiyongPai = new majiang.Datas.PaiChi();
        }

        /**
         * gameStart
         * 游戏开始时
         */
        public gameStart() {
            //初始化 游戏开始时的数据
            majiang.Controllers.Play.initPlayGameData();

            this.fanshu = 0;
            this.hupaishu = 0;

            this.scoreBoard.gameStart();
            this.hupaiArea.gameStart();
            this.xuanArea.gameStart();
        }

        /**
         * gameOver
         */
        public gameOver() {
            this.scoreBoard.timerStop();
            majiang.Datas.Playing.allFan = this.fanshu;
            majiang.Datas.Playing.allHu = this.hupaishu;

            majiang.Controllers.GameMain.balance.toOverMain();
            majiang.Controllers.GameMain.openBalance();
        }

        /**
         * canHupai
         */
        public isCanHupai(isCan:boolean) {
            if(isCan){
                this.hupaiBtn.icon = "huIcon_png";
                this.hupaiBtn.isCanHu = true;
            }else{
                this.hupaiBtn.icon = "not_huIcon_png";
                this.hupaiBtn.isCanHu = false;
            }
        }

        /**
         * hupai
         * 玩家胡牌
         */
        public hupai() {
            var hupai:any = this.hupaiArea.getHupaiFanshu();
            this.fanshu += hupai.fanshu;
            this.hupaishu ++;
            
            this.hupaiArea.hupai();

            egret.Tween.get(this.hupaiArea).wait(2000).call(()=>{
                this.hupaiArea.initHupaiArea();
            },this);

            this.scoreBoard.hupai(hupai.paixingArr);
        }
    }
}